import Vue from 'vue';
import Vuex from 'vuex';

Vue.use(Vuex);

const store = new Vuex.Store({
    state: {
        currentSong: {}, //最新音乐的储存
        SongsList: [],
        songsListColor: -1, //播放歌单当前的index
        currentSongComment: {},

        recordPlaysongs: [], //历史记录的存放

        currentTime: 0,
        //播放器的状态
        isPlay: false,
        // showWords: false,
    },

    mutations: {
        setCurrentSong(state, date) {
            if (date.id === state.currentSong.id) {
                state.currentTime = 0;
            } else {
                state.currentSong = date;
            }
        },

        setSongsList(state, List) {
            state.SongsList = List;
        },
        setSongsListColor(state, index) {
            state.songsListColor = index;
        },
        setcurrentSongComment(state, comment) {
            state.currentSongComment = comment;
        },
        setRecordPlaylist(state, song) {
            if (song instanceof Array) {
                state.recordPlaysongs = [];
                return;
            } else {
                const RecordSongs = state.recordPlaysongs.findIndex(
                    (item) => item.id === song.id
                );

                if (RecordSongs > -1) {
                    state.recordPlaysongs.splice(RecordSongs, 1);
                }
                state.recordPlaysongs.unshift(song);
            }
        },
        setCurrentTime(state, time) {
            state.currentTime = time;
        },
        setplaystatus(state, status) {
            state.isPlay = status;
        },
    },
});

export default store;